#!/bin/sh
### BEGIN INIT INFO
# Provides:          wfs
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5 S
# Default-Stop:      0 1 6
# Short-Description: WFS WAN Failover Script
# Description:       WFS allows active connection monitoring
#                    and automatic failover in dual WAN setups.
### END INIT INFO

CONFIG=/etc/wfs/wfs.conf

if [ -e "$CONFIG" ]
then
    . "$CONFIG"
fi

stop_wfs () {

    if [ -e "$PIDFILE" ]
    then
        echo "Stopping wfs..."
        kill `cat "$PIDFILE"`
        rm "$PIDFILE"
    else
        echo "WFS is not running."
        exit 1
    fi
}

start_wfs () {

    if [ -e "$PIDFILE" ]
    then
        echo "WFS is already running."
        exit 1
    else
        echo "Starting wfs..."
        /usr/bin/wfs
    fi
}

usage () {

    echo "Usage: $0 [ start | stop | restart ] "
}


case "$1" in
    start)
            start_wfs
            ;;
    stop)
            stop_wfs
            ;;
    restart)
            stop_wfs
            start_wfs
            ;;
    *)
            usage
            ;;
esac 


